import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';

class BMFImageUtil {
  static Future<Uint8List?> widgetToUnit8List(Widget widget) async {
    GlobalKey globalKey = new GlobalKey();
    RenderObject? boundary = globalKey.currentContext!.findRenderObject();
    var image = await (boundary as RenderRepaintBoundary)
        .toImage(pixelRatio: window.devicePixelRatio);
    ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
    Uint8List pngBytes = byteData!.buffer.asUint8List();
    return pngBytes;
  }
}
